﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Security2;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class SYS_INFO
    {
        private static long _count = -1L;
        private string m_Application;
        private DateTime m_Created;
        private string m_Description;
        private static string m_Guid_ID;
        private string m_SysInfo_ID;
        private int m_Type;
        private string m_Version;

        public SYS_INFO()
        {
            this.m_SysInfo_ID = "";
            this.m_Application = "";
            this.m_Version = "";
            this.m_Type = 0;
            this.m_Created = DateTime.Now;
            this.m_Description = "";
            m_Guid_ID = "";
        }

        public SYS_INFO(string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description)
        {
            this.m_SysInfo_ID = SysInfo_ID;
            this.m_Application = Application;
            this.m_Version = Version;
            this.m_Type = Type;
            this.m_Created = Created;
            this.m_Description = Description;
            m_Guid_ID = Guid_ID;
        }

        private static void Cal()
        {
            GetInfo();
            _count = Convert.ToInt64(MyEncryption.Decrypt(m_Guid_ID, "zxc123", true));
            if (_count == 0L)
            {
                SqlHelper helper = new SqlHelper();
                helper.CommandType = CommandType.Text;
                helper.ExecuteNonQuery("Update [SYS_INFO] set [Guid_ID]='RYhjrnjcBlI='");
            }
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { this.m_SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Delete", myParams, myValues);
        }

        public string Delete(string SysInfo_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string SysInfo_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_INFO_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string SysInfo_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_INFO_Delete", myParams, myValues);
        }

        public bool Exist(string SysInfo_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_INFO_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get()
        {
            string str = "";
            SqlHelper helper = new SqlHelper();
            helper.Extract();
            helper.CommandType = CommandType.Text;
            SqlDataReader reader = helper.ExecuteReader("select * from[" + helper.Database + "].dbo.SYS_INFO");
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SysInfo_ID = Convert.ToString(reader["SysInfo_ID"]);
                    this.m_Application = Convert.ToString(reader["Application"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Type = Convert.ToInt32(reader["Type"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                reader.Dispose();
                helper.Close();
            }
            return str;
        }

        public string Get(string SysInfo_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_INFO_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SysInfo_ID = Convert.ToString(reader["SysInfo_ID"]);
                    this.m_Application = Convert.ToString(reader["Application"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Type = Convert.ToInt32(reader["Type"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string SysInfo_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "SYS_INFO_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SysInfo_ID = Convert.ToString(reader["SysInfo_ID"]);
                    this.m_Application = Convert.ToString(reader["Application"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Type = Convert.ToInt32(reader["Type"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    m_Guid_ID = Convert.ToString(reader["Guid_ID"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string SysInfo_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@SysInfo_ID" };
            object[] myValues = new object[] { SysInfo_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "SYS_INFO_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SysInfo_ID = Convert.ToString(reader["SysInfo_ID"]);
                    this.m_Application = Convert.ToString(reader["Application"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Type = Convert.ToInt32(reader["Type"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    m_Guid_ID = Convert.ToString(reader["Guid_ID"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public static string GetInfo()
        {
            string str = "";
            SqlHelper helper = new SqlHelper();
            helper.CommandType = CommandType.Text;
            SqlDataReader reader = helper.ExecuteReader("select  Guid_ID from dbo.SYS_INFO");
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_Guid_ID = Convert.ToString(reader["Guid_ID"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string GetInfo(string database)
        {
            string str = "";
            SqlHelper helper = new SqlHelper();
            helper.CommandType = CommandType.Text;
            SqlDataReader reader = helper.ExecuteReader("select * from [" + database + "].dbo.SYS_INFO");
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SysInfo_ID = Convert.ToString(reader["SysInfo_ID"]);
                    this.m_Application = Convert.ToString(reader["Application"]);
                    this.m_Version = Convert.ToString(reader["Version"]);
                    this.m_Type = Convert.ToInt32(reader["Type"]);
                    this.m_Created = Convert.ToDateTime(reader["Created"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                reader.Dispose();
                helper.Close();
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("SYS_INFO_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { this.m_SysInfo_ID, this.m_Application, this.m_Version, this.m_Type, this.m_Created, this.m_Description, m_Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { this.m_SysInfo_ID, this.m_Application, this.m_Version, this.m_Type, this.m_Created, this.m_Description, m_Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_INFO_Insert", myParams, myValues);
        }

        public string Insert(string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_INFO_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_INFO_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("SYS_INFO", "SYS_INFOID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { this.m_SysInfo_ID, this.m_Application, this.m_Version, this.m_Type, this.m_Created, this.m_Description, m_Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { this.m_SysInfo_ID, this.m_Application, this.m_Version, this.m_Type, this.m_Created, this.m_Description, m_Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_INFO_Update", myParams, myValues);
        }

        public string Update(string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_INFO_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_INFO_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string SysInfo_ID, string Application, string Version, int Type, DateTime Created, string Description, string Guid_ID)
        {
            string[] myParams = new string[] { "@SysInfo_ID", "@Application", "@Version", "@Type", "@Created", "@Description", "@Guid_ID" };
            object[] myValues = new object[] { SysInfo_ID, Application, Version, Type, Created, Description, Guid_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_INFO_Update", myParams, myValues);
        }

        public string Application
        {
            get
            {
                return this.m_Application;
            }
            set
            {
                this.m_Application = value;
            }
        }

        public static long Count
        {
            get
            {
                Cal();
                return _count;
            }
        }

        public DateTime Created
        {
            get
            {
                return this.m_Created;
            }
            set
            {
                this.m_Created = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public static string Guid_ID
        {
            get
            {
                return m_Guid_ID;
            }
            set
            {
                m_Guid_ID = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class SYS_INFO";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public string SysInfo_ID
        {
            get
            {
                return this.m_SysInfo_ID;
            }
            set
            {
                this.m_SysInfo_ID = value;
            }
        }

        public int Type
        {
            get
            {
                return this.m_Type;
            }
            set
            {
                this.m_Type = value;
            }
        }

        public string Version
        {
            get
            {
                return this.m_Version;
            }
            set
            {
                this.m_Version = value;
            }
        }
    }
}

